using MilkShake;
using UnityEngine;

public class Explosion : MonoBehaviour
{
	public Collider2D killzone;

	public ParticleSystem effect;

	public ShakePreset shake;

	public GameObject holePrefab;

	public float damage = 10f;

	public float forceY = 1f;

	public float force = 1000f;

	public Vector2 randomForceY = Vector2.zero;

	private void Awake()
	{
		Active();
	}

	public void Active()
	{
		Object.Destroy(base.gameObject, 6f);
		Object.Destroy(Object.Instantiate(effect, base.transform.position, Quaternion.identity), 5f);
		killzone.enabled = true;
		Shaker.ShakeAll(shake);
		if (holePrefab != null)
		{
			Object.Instantiate(holePrefab, base.transform.position, Quaternion.identity);
		}
		Object.Destroy(killzone, 0.2f);
	}

	private void OnTriggerEnter2D(Collider2D collision)
	{
		if (!killzone.enabled || !(collision.tag == "Zombie"))
		{
			return;
		}
		Chicken component2;
		if (collision.TryGetComponent<Zombie>(out var component))
		{
			component.body.health -= damage;
			BodyPart[] bodyParts;
			if (component.body.health <= 0f)
			{
				component.body.Die();
				Vector3 position = component.transform.position;
				if (randomForceY != Vector2.zero)
				{
					position.y += Random.Range(randomForceY.x, randomForceY.y);
				}
				else
				{
					position.y += forceY;
				}
				Vector3 normalized = (position - base.transform.position).normalized;
				bodyParts = component.body.bodyParts;
				foreach (BodyPart bodyPart in bodyParts)
				{
					if ((bool)bodyPart)
					{
						if (bodyPart.name == "ChestRb")
						{
							bodyPart.rb.AddForce(force * normalized);
						}
						bodyPart.damageShare = Random.Range(0.2f, 1f);
						bodyPart.Bleed(bodyPart.transform.position);
						continue;
					}
					break;
				}
				return;
			}
			bodyParts = component.body.bodyParts;
			foreach (BodyPart bodyPart2 in bodyParts)
			{
				if ((bool)bodyPart2)
				{
					bodyPart2.damageShare = Random.Range(0.1f, 0.5f);
					bodyPart2.Bleed(bodyPart2.transform.position);
				}
			}
			string animation = "fallDownBack";
			if (damage < component.health * 0.7f)
			{
				animation = "knockback";
			}
			if (base.transform.position.x > component.transform.position.x)
			{
				animation = "fallDownFront";
				force = 0f;
			}
			component.Knockback(force * 2f, animation);
		}
		else if (collision.TryGetComponent<Chicken>(out component2))
		{
			component2.body.Die();
		}
	}
}
